package cn.zhaoyuening.hadoopdemo.reducer;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.log4j.Logger;
import sun.rmi.runtime.Log;

import java.io.IOException;
import java.util.logging.Level;

public class MaxTemperatureReducer extends Reducer<Text, DoubleWritable,Text,DoubleWritable>{
    private static Logger logger = Logger.getLogger(MaxTemperatureReducer.class);
    @Override
    protected void reduce(Text key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException {

        double maxVal = Double.MIN_VALUE;
        for (DoubleWritable dw :
                values) {
            maxVal = Math.max(maxVal, dw.get());
        }
        if (maxVal == Double.MIN_VALUE) {
            return;
        }
        logger.info(key.toString()+"max = "+maxVal);
        context.write(key,new DoubleWritable(maxVal));
    }
}
